home *** CD-ROM | disk | FTP | other *** search
- Path: nntp.teleport.com!usenet
- From: GHouck <hksys@teleport.com>
- Newsgroups: comp.lang.c
- Subject: Re: HELP- PASSING STRUCTURE IN FUNCTION PROTOTYPE?
- Date: 21 Apr 1996 07:59:12 GMT
- Organization: systems hk
- Message-ID: <4lcpsg$9ta@nadine.teleport.com>
- References: <31784e1f.4961188@news.planet.net>
- NNTP-Posting-Host: ip-pdx14-54.teleport.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
-
- cygnusx@planet.net (David) wrote:
- [snip]
- >When I try to compile I get only one error. It is at the beginning of
- >the function prototype (morethan) and this is the error statment?? .
- > [ ) expected ] .
- >Is this somthing with the way I wrote the program or just something in
- >this line? I am not sure this is a good way to go about this program .
- >
- >struct employee {
- > char first[10];
- > char last [10];
- > float salary;
- > };
- >
- >morethan(struct employee,float);
- >
- >main(){
- > int ctr;
- > struct employee data[4];
- > for (ctr=0;ctr<4;ctr++)
- > {printf("please enter first name:\n");
- [snip]
- > for (ctr=0;ctr<4;ctr++)
- > {printf("%s\n",data[ctr].first);
- > printf("%s\n",data[ctr].last);
- > printf("%f\n",data[ctr].salary);}
- > morethan(data[4],1000);
- > return 0;}
- > morethan (struct employee a[],b) /* error is on this line */
- > { for(i=0;i<4;i++)
- > if(data[i].salary > b)
- >
- > printf("%s",data[i].first);
- > printf("%s",data[i].last);}
-
-
- David,
-
- Your function prototype is actually the line just below your
- structure declaration. In it you are stating that the function
- accepts a structure 'employee' and a 'float' type; yet, when
- you define your function at the bottom, you specify an 'array
- of structs' and have given no type for 'b'.
-
- In your prototype, I would suggest:
-
- int morethan( struct employee data[], float limit );
-
- Then in your function definition below:
-
- int morethan ( struct employee data[], float b )
- {
- int i;
-
- for( i=0; i<4; i++ ) {
- if( data[i].first > b ) {
- printf( ...
- printf( ...
- }
- }
- }
-
-
-
-
- Yours, Geoff Houck
-
-
-
-